package br.ufrpe.bsi.pvs.xml.response;

import org.jdom2.Attribute;
import org.jdom2.Document;
import org.jdom2.Element;

import br.ufrpe.bsi.pvs.xml.XMLUtil;

public class AddedResponseProcess implements ResponseProcess {

	@Override
	public Object response(Element response) {
		Element messageElement = response.getChild(XMLUtil.ELEM_MSG);
		return messageElement.getValue();
	}

	/** generates a default add request xml document */
	public static Document getAddedResponseDocument(String className) {
		Document document = new Document();

        Element root = new Element(XMLUtil.ELEM_ROOT);
        Element response = new Element(XMLUtil.ELEM_RESPONSE);

        Attribute responseName = new Attribute(XMLUtil.ATTR_NAME, XMLUtil.ADDED);
        response.setAttribute(responseName);
                
        Element message = new Element(XMLUtil.ELEM_MSG);
        message.addContent(className + " adicionado com sucesso!");        
        
        response.setContent(message);
        root.addContent(response);
        document.setRootElement(root);
        
        return document;
	}

}
